package io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/** 多字节文件复制(块读写)   */
public class CopyDemo2 {
    public static void main(String[] args) throws IOException {
        FileInputStream fis=new FileInputStream("OIP.jpg");
        FileOutputStream fox = new FileOutputStream("OIP_cp2.jpg");
        long start = System.currentTimeMillis();
        int len ;
        byte[]data =new byte[1024*100];//100kb
        while((len=fis.read(data))!=-1){
            // fox.write(data)最后一次可能会有脏数据
            fox.write(data,0,len);//从data[0]开始写入len个字节
        }

        System.out.println("开始复制");
        Long end = System.currentTimeMillis();
        System.out.println("复制完毕"+(end-start)+"ms");
        fis.close();
        fox.close();
    }
}
